#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2022/8/5 11:57
# @Author  : 招财大龙猫
# @File    : pandas_sql.py
# @Description :
import pandas as pd
import sqlalchemy

engine = sqlalchemy.create_engine('postgresql+psycopg2://postgres:sams111@127.0.0.1/sams', encoding='utf-8', echo=False)
data_list = [{'a': 1, 'b': 2}, {'a': 1, 'b': 2}]
df = pd.DataFrame(data_list)
df.columns = df.columns.str.lower()
df.to_sql('tablename', engine, index=False, if_exists='append')


df = pd.read_csv(r'bd.csv')
df['exist1'] = df['0'].str.contains('|'.join(df['1'].dropna().tolist()))
df['exist2'] = df['2'].str.contains('|'.join(df['3'].dropna().tolist()))
df.to_excel('tb.xlsx', index=False)
